package com.young.common.client.config.web;

import com.young.common.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 环境变量手动刷新
 * Created by Admin on 2021/6/20.
 */
@Controller
@RequestMapping("/config/client")
public class EnvironmentRefreshController {

    private static final Logger logger = LoggerFactory.getLogger(EnvironmentRefreshController.class);

    @Autowired
    ContextRefresher contextRefresher;


    /**
     * 刷新应用配置
     * @return
     */
    @PostMapping("/refreshEnvironment")
    @ResponseBody
    public Object refresh() {
        logger.info("[刷新应用配置] go.");
        contextRefresher.refresh();
        logger.info("[刷新应用配置] 完成刷新.");
        return Result.buildSuccess();
    }

}
